from selenium import webdriver
import ddt
import unittest
from selenium.webdriver.common.by import By
from readder16 import readzsmc
import time

@ddt.ddt
class Denglu(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(5)
    def tearDown(self):
        self.driver.quit()

    stream_info = readzsmc()
    @ddt.data(*stream_info)
    def test_denglu(self,list):
        try:
            driver = self.driver
            driver.get("http://192.168.46.5:18089/login")
            driver.find_element(By.NAME,'username').send_keys("XTGLY")
            driver.find_element(By.CLASS_NAME,'password').send_keys("123456")
            driver.find_element(By.ID,"signIn").click()

            # 在商品信息页面点击“商品分类”按钮；
            driver.find_element(By.PARTIAL_LINK_TEXT,"商品分类").click()
            time.sleep(2)
            # 点击“新增”按钮；
            driver.find_element(By.XPATH,'//*[@id="app"]/div/div[2]/section/div/div[2]/div[3]/button').click()
            # 输入框输送商品分类名称
            driver.find_element(By.CLASS_NAME,"el-input__inner").send_keys(list[0])
            #点击保存
            driver.find_element(By.XPATH,'/html/body/div[2]/div/div[3]/div/button[1]').click()
            time.sleep(1)
            # 获取提示信息文本
            a = driver.find_element(By.CLASS_NAME,"el-form-item__error").text
            print(a)
            # 断言判断文本和数据驱动中的期待信息是否一致
            self.assertEqual(a,list[1])
            print("用例执行成功")
        except:
            # 不成功截图
            self.driver.get_screenshot_as_file(r"C:\Users\speakj\Pictures\Camera Roll\\asserfail.png")
            print("用例执行失败")


if __name__ == '__main__':
    unittest.main()